package org.robert.export_client.excel.metadata;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.robert.export_client.excel.entity.WriteSheet;

import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
import java.util.Map;

/**
 * WorkbookWrite:
 *
 * @author zhaoshengtao
 * @date 2024/01/22
 */
@Slf4j
@Data
@NoArgsConstructor
public class AbstractWorkbookWrite {

    protected AbstractWorkbookBuilder workbookBuilder;

    public AbstractWorkbookWrite(AbstractWorkbookBuilder workbookBuilder) {
        this.workbookBuilder = workbookBuilder;
    }

    public AbstractSheetBuilder createSheet(String sheetName, Class<?> clazz, Map<String, Map<String, String>> dictMap) throws Exception {

        return this.workbookBuilder.createSheet(sheetName, clazz, dictMap);
    }

    public void write(List<?> data, WriteSheet writeSheet) throws Exception {
        AbstractSheetBuilder sheetBuilder = writeSheet.getSheetBuilder();
        sheetBuilder.doWrite(data);
    }

    public void finish(AbstractWriteSheet writeSheet) {
        writeSheet.sheetBuilder.finish();
    }

}
